/**
 * Created by CHENRI4 on 10/19/2016.
 */
Ext.define('sso.admin.user.view.UserSearchBarView',{
    extend:'Ext.panel.Panel',
    alias: 'widget.UserSearchBarView',
    id: 'userSearchBar',
    ui: 'default',
    border:true,
    layout: 'anchor',
    Cls: 'content',
    collapseDirection: 'left',
    collapsed: true,
    collapsible: true,
    title: 'Search',
    initComponent: function() {
        var me = this;
        var userIdStore = Ext.create('Ext.data.Store', {
            fields: ['userId', 'userIdValue'],
        });
        userIdStore.add({userId: 'ALL', userIdValue: ''});

        var displayNameStore = Ext.create('Ext.data.Store', {
            fields: ['name', 'nameValue'],
        });
        displayNameStore.add({name: 'ALL', nameValue: ''});
        Ext.applyIf(me, {
            items: [{
                xtype: 'form',
                border: false,
                margin:10,
                cls: 'leftRightMargin',
                id: 'userSearchForm',
                ui: 'leftMenuContent',
                layout: 'anchor',
                defaults: {
                    anchor: '100%'
                },
                items: [
                    {
                        xtype: 'combobox',
                        id: 'userSearchUserIdCombo',
                        fieldLabel: 'User Id:',
                        name: 'userId',
                        queryMode : 'local',
                        triggerAction : "all",
                        displayField : 'userId',
                        valueField : 'userIdValue',
                        store: userIdStore,
                        listeners: {
                            afterRender: function(combo) {
                                var firstValue = userIdStore.first();
                                combo.setValue(firstValue);
                            }
                        }
                    },
                    {
                        xtype: 'combobox',
                        id: 'userSearchDisplayNameCombo',
                        fieldLabel: 'Name:',
                        name: 'name',
                        queryMode : 'local',
                        triggerAction : "all",
                        displayField : 'name',
                        valueField : 'nameValue',
                        store: displayNameStore,
                        listeners: {
                            afterRender: function(combo) {
                                var firstValue = displayNameStore.first();
                                combo.setValue(firstValue);
                            }
                        }
                    },
                    {
                        xtype:'numberfield',
                        fieldLabel:'Phone',
                        name:'phone'
                    },
                    {
                        xtype:'datefield',
                        fieldLabel:'FromCreateTime',
                        name:'gtDate',
                        format:'Y-m-d'
                    },
                    {
                        xtype:'datefield',
                        fieldLabel:'ToCreateTime',
                        name:'ltDate',
                        format:'Y-m-d'
                    },
                    {
                        xtype: 'container',
                        cls: 'buttonSearch',
                        layout: {
                            type: 'hbox',
                            align: 'stretch',
                            pack: 'end',
                        },
                        padding:'0 10 0 0',
                        style:{
                            float:'right',
                        },
                        items: [
                            {
                                xtype: 'button',
                                id: 'btnUserReset',
                                width: 'auto',
                                text: 'Reset',
                            },
                            {
                                xtype: 'tbspacer',
                                width: 10
                            },
                            {
                                xtype: 'button',
                                id: 'btnUserSearch',
                                width: 'auto',
                                text: 'Search',
                                handler: function(btn){
                                    var searchCondition = btn.up('form').getForm().getValues();
                                    me.fireEvent('searchClick',searchCondition);
                                }
                            }
                        ]
                    }
                ]
            }]
        });
        me.callParent(arguments);
    }
})